package com.Day13.aaa;

import java.util.List;

/**
 * @author: 若若叶
 * @date: 2021/7/29 7:03
 * FileName: Consumer
 * Description: 模拟消费者，负责消耗集合的元素
 */
public class Consumer implements Runnable {
    private List list;

    public Consumer(List list) {
        this.list = list;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (list) {
                if (list.size() % 2 == 1) {
                    try {
                        list.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                Object o = new Object();
                list.add(o);
                System.out.println(Thread.currentThread().getName() + "--->" + "仓库里有" + list.size() + "个产品。");
                list.notify();
            }
        }
    }
}
